/**
 * @(#)VersionTask.java 1.0 2013/9/4
 * Copyright 2013 PD, Inc. All rights reserved.
 */
package cn.broadin.app.hotel.task;


import android.os.AsyncTask;
import android.util.Log;
import cn.broadin.app.hotel.factory.ApplicationFactory;
import cn.broadin.app.hotel.startWebapp.LoadActivity;
import cn.broadin.app.hotel.util.PDUtils;
import cn.broadin.app.hotel.version.VersionInfo;

import com.alibaba.fastjson.JSON;

/**
 * VersionTask 版本信息task
 * @author fenghui
 *
 */
public class VersionTask extends AsyncTask<Void, Void, Void>{

	private static final String TAG = "VersionTask";		//log tag
	private LoadActivity loadActivity;						//处理完后调用该类中方法
	private String httpResult = "";							//http请求结果
	
	public VersionTask(LoadActivity activity) {
		loadActivity = activity;
	}
	
	@Override
	protected void onPreExecute() {
		super.onPreExecute();
	}

	@Override
	protected Void doInBackground(Void... params) {
		//请求版本信息
		String versionUrl = ApplicationFactory.getApplication().VERSIONURL() + "version.json";
		httpResult = PDUtils.getInstance().getHttpRequest(versionUrl);
		Log.d(TAG, "getResut:>> " + httpResult);
		return null;
	}
	
	@Override
	protected void onPostExecute(Void result) {
		VersionInfo version = null;
		try {
			version = (VersionInfo)JSON.parseObject(httpResult, VersionInfo.class);
		} catch (Exception e) {
			Log.e(TAG, "get version data error." + e.getMessage());
		}finally {
			loadActivity.postVersionData(version);			//返回消息给LoadActivity
		}
	}
}